interface tablsType {
  value: string;
  icons: string;
  color?: string;
}
/** tabs绑定的值 */
const tabsBindValues = ref<string>('单元');
const unitPermissionsRight = ref<boolean>(false);
const treePermission = ref<boolean>(false);
const ElCheckTag = (value: number) => {
  if (value === 1) {
    unitPermissionsRight.value = true;
  } else {
    unitPermissionsRight.value = false;
  }
};
const ElRadioTag = (value: number) => {
  if (value === 1) {
    treePermission.value = true;
  } else {
    formData.formFields.rightdataName = '';
  }
};

/** 设置group表单 */
const formGroup = reactive<Namespace.FormType>({
  loadKey: true,
  formFields: {
    unitCode: '',
    unitName: '',
  },
  formRules: [
    [
      {
        title: '单元编号',
        required: true,
        field: 'unitCode',
        placeholder: '请输入单元编号',
        type: 'text',
      },
      {
        title: '标题',
        required: false,
        field: 'unitName',
        placeholder: '请输入标题',
        type: 'text',
      },
    ],
  ],
});

/** 单元列表查询表单写成静态 */
const formData = reactive<Namespace.FormType>({
  loadKey: true,
  formFields: {
    unitCode: '',
    unitName: '',
    parentId: '',
    dataStatus: '',
    unitRight: '',
    dataId: '',
    dataTable: '',
    unitPublish: '',
    unitStatus: '',
    rightdataType: '',
    rightdataName: '',
    unitContent: '',
    remark: '',
    menuPermissions: '',
  },
  formRules: [
    [
      {
        title: '单元编号',
        required: true,
        field: 'unitCode',
        placeholder: '请输入单元编号',
        type: 'text',
      },
      {
        title: '标题',
        required: false,
        field: 'unitName',
        placeholder: '请输入标题',
        type: 'text',
      },
    ],
    [
      {
        title: '父级单元',
        required: true,
        dataKey: 'value',
        dataName: 'label',
        field: 'parentId',
        placeholder: '请选择父级单元',
        type: 'selectv2',
        data: [],
      },
      {
        dataKey: 'key',
        dataName: 'value',
        title: '显示模式',
        required: true,
        placeholder: '请选择显示模式',
        field: 'unitStatus',
        data: [
          { key: 0, value: '表单' },
          { key: 1, value: '组合' },
        ],
        type: 'radio',
      },
    ],
    [
      {
        dataKey: 'key',
        dataName: 'value',
        title: '需要权限',
        required: true,
        placeholder: '请选择是否需要权限',
        field: 'unitRight',
        data: [
          { key: 1, value: '使用' },
          { key: 0, value: '未使用' },
        ],
        type: 'radio',
        onChange: ElCheckTag,
      },
      {
        title: '权限标识',
        required: true,
        field: 'menuPermissions',
        placeholder: '请输入权限标识',
        type: 'text',
      },
    ],
    [
      {
        type: 'select',
        dataKey: 'key',
        dataName: 'value',
        default: '', // 默认值 需要异步填写
        title: '数据区域',
        required: false,
        placeholder: '请选择数据区域',
        field: 'dataId',
        data: [],
      },
      {
        title: '数据映射表',
        required: false,
        field: 'dataTable',
        placeholder: '请输入数据映射表',
        type: 'text',
      },
    ],
    [
      {
        dataKey: 'key',
        dataName: 'value',
        title: '是否发布',
        required: false,
        field: 'unitPublish',
        data: [
          { key: 1, value: '发布' },
          { key: 0, value: '未发布' },
        ],
        type: 'radio',
      },
      {
        dataKey: 'key',
        dataName: 'value',
        title: '数据模式',
        required: true,
        placeholder: '请选择数据模式',
        field: 'dataStatus',
        data: [
          { key: 0, value: '请求' },
          { key: 1, value: 'SQL' },
        ],
        type: 'radio',
      },
    ],
    [
      {
        dataKey: 'key',
        dataName: 'value',
        title: '数据权限',
        required: true,
        placeholder: '请选择数据权限',
        field: 'rightdataType',
        data: [
          { key: 1, value: '启用' },
          { key: 0, value: '关闭' },
        ],
        type: 'radio',
        onChange: ElRadioTag,
      },
      {
        title: '数据权限',
        required: false,
        field: 'rightdataName',
        placeholder: '请输入数据权限',
        type: 'text',
        readonly: true,
      },
    ],
    [
      {
        title: '备注',
        required: false,
        field: 'remark',
        colSize: 12,
        type: 'textarea',
        minRows: 5,
      },
    ],
    [
      {
        title: '数据表达式',
        field: 'unitContent',
        type: 'webEditor',
        placeholder: '请输入数据权限',
        language: 'sql',
        switch: true,
      },
    ],
  ],
});
/** 单元权限标识 */
const formDataUnit = reactive<Namespace.FormType>({
  loadKey: true,
  formFields: {
    menuPermissions: '',
  },
  formRules: [
    [
      {
        title: '权限标识',
        required: true,
        field: 'menuPermissions',
        placeholder: '请输入权限标识',
        type: 'text',
        colSize: 12,
      },
    ],
  ],
});

export {
  tabsBindValues,
  formData,
  formGroup,
  tablsType,
  unitPermissionsRight,
  formDataUnit,
  treePermission,
};
